feat: add stats/strided/selmax#11701
Conversation
Coverage Report
The above coverage report was generated for the changes in this PR. |
|
/stdlib merge |
|
/stdlib update-copyright-years |
| /** | ||
| * Mask array. | ||
| */ | ||
| type MaskArray = NumericArray | Collection<number> | AccessorArrayLike<number>; |
There was a problem hiding this comment.
This isn't correct. For the "generic" API, we simply mask based on truthiness.
| type MaskArray = NumericArray | Collection<number> | AccessorArrayLike<number>; | |
| type MaskArray = Collection<unknown> | AccessorArrayLike<unknown>; |
| selmax( x.length, x, ( x: number ): number => x, mask, 1 ); // $ExpectError | ||
| } | ||
|
|
||
| // The compiler throws an error if the function is provided a fourth argument which is not a numeric array... |
There was a problem hiding this comment.
| // The compiler throws an error if the function is provided a fourth argument which is not a numeric array... | |
| // The compiler throws an error if the function is provided a fourth argument which is not an array... |
| selmax.ndarray( x.length, x, 1, ( x: number ): number => x, mask, 1, 0 ); // $ExpectError | ||
| } | ||
|
|
||
| // The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a numeric array... |
There was a problem hiding this comment.
| // The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a numeric array... | |
| // The compiler throws an error if the `ndarray` method is provided a fifth argument which is not an array... |
| strideX: integer | ||
| Stride length for `x`. | ||
|
|
||
| mask: Array<number>|TypedArray |
There was a problem hiding this comment.
| mask: Array<number>|TypedArray | |
| mask: Array|TypedArray |
| offsetX: integer | ||
| Starting index for `x`. | ||
|
|
||
| mask: Array<number>|TypedArray |
There was a problem hiding this comment.
| mask: Array<number>|TypedArray | |
| mask: Array|TypedArray |
| * @param {PositiveInteger} N - number of indexed elements | ||
| * @param {NumericArray} x - input array | ||
| * @param {integer} strideX - `x` stride length | ||
| * @param {NumericArray} mask - mask array |
There was a problem hiding this comment.
| * @param {NumericArray} mask - mask array | |
| * @param {Collection} mask - mask array |
| * @param {NumericArray} x - input array | ||
| * @param {integer} strideX - stride length for `x` | ||
| * @param {NonNegativeInteger} offsetX - starting index for `x` | ||
| * @param {NumericArray} mask - mask array |
There was a problem hiding this comment.
| * @param {NumericArray} mask - mask array | |
| * @param {Collection} mask - mask array |
| var mask0 = new BooleanArray([ | ||
| true, true, true, true, true, true, false, false | ||
| ]); |
There was a problem hiding this comment.
| var mask0 = new BooleanArray([ | |
| true, true, true, true, true, true, false, false | |
| ]); | |
| var mask0 = new BooleanArray( [ true, true, true, true, true, true, false, false ] ); |
No splitting over multiple lines like this.
|
|
||
| Note that indexing is relative to the first index. To introduce offsets, use [`typed array`][mdn-typed-array] views. | ||
|
|
||
| <!-- eslint-disable stdlib/capitalized-comments --> |
There was a problem hiding this comment.
| <!-- eslint-disable stdlib/capitalized-comments --> | |
| <!-- eslint-disable stdlib/capitalized-comments, max-len --> |
|
|
||
| * * * | ||
|
|
||
| ## See Also | ||
|
|
||
| - <span class="package-name">[`@stdlib/stats/strided/max`][@stdlib/stats/strided/max]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array.</span> | ||
| - <span class="package-name">[`@stdlib/stats/strided/mskmax`][@stdlib/stats/strided/mskmax]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array according to a mask.</span> | ||
| - <span class="package-name">[`@stdlib/stats/strided/nanmax`][@stdlib/stats/strided/nanmax]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array, ignoring NaN values.</span> |
There was a problem hiding this comment.
| * * * | |
| ## See Also | |
| - <span class="package-name">[`@stdlib/stats/strided/max`][@stdlib/stats/strided/max]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array.</span> | |
| - <span class="package-name">[`@stdlib/stats/strided/mskmax`][@stdlib/stats/strided/mskmax]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array according to a mask.</span> | |
| - <span class="package-name">[`@stdlib/stats/strided/nanmax`][@stdlib/stats/strided/nanmax]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array, ignoring NaN values.</span> |
| [@stdlib/stats/strided/max]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/max | ||
|
|
||
| [@stdlib/stats/strided/mskmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/mskmax | ||
|
|
||
| [@stdlib/stats/strided/nanmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/nanmax | ||
|
|
There was a problem hiding this comment.
| [@stdlib/stats/strided/max]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/max | |
| [@stdlib/stats/strided/mskmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/mskmax | |
| [@stdlib/stats/strided/nanmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/nanmax |
kgryte
left a comment
There was a problem hiding this comment.
For the most part, this is coming along. One thing that should be changed throughout is that mask should be a boolean array. So, instead of
var mask = bernoulli( x.length, 0.8, {
'dtype': 'generic'
});do
var mask = new BooleanArray( bernoulli( x.length, 0.8 ) );Instead of
var mask = [ 1, 1, 0, 1 ];do
var mask = [ true, true, false, true ];Otherwise, your text which states that an element is only considered valid if a mask element is true is inconsistent with the examples, which are primarily showing numeric arrays.
It is fine, if operationally within this package, we accept non-boolean arrays, but all of our examples and docs should use boolean arrays or generic arrays containing booleans in order to communicate user expectation.
454641e to
6f347cc
Compare
Resolves none.
Description
This pull request:
stats/strided/selmaxRelated Issues
This pull request has the following related issues:
Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
{{TODO: add disclosure if applicable}}
@stdlib-js/reviewers